package com.eight.homepage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.common.pojo.TbZone;
import com.eight.common.vo.Result;
import com.eight.homepage.service.TbZoneService;
import com.eight.homepage.vo.TbZoneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * @author 向文豪
 * @program: eight-education-parent
 * @description:
 * @date 2023/5/26 16:03
 */
@RestController
@RequestMapping("/home/zone")
@Api(tags = "专区")
public class TbZoneController {

    @Autowired
    private TbZoneService tbZoneService;

    @PostMapping("/getAllZone/{currentPage}/{pageSize}")
    @ApiOperation("分页查询专区")
    public Result getAllZone(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody TbZoneVo tbZoneVo){

        Page<TbZone> page = tbZoneService.findPage(currentPage, pageSize, tbZoneVo);
        return Result.success(page);
    }

    @PostMapping("/changeStatus/{id}/{isDisable}")
    @ApiOperation("修改状态")
    public Result changeStatus(@PathVariable  String id,@PathVariable Integer isDisable){
        int i = tbZoneService.updateStatus(id, isDisable);
        return Result.success();
    }

    @PostMapping("/deleteZone")
    @ApiOperation(value = "删除专区")
    public Result delete(@RequestBody TbZone tbZone){
        String id = tbZone.getId();
       // System.out.println(id);
        int delete = tbZoneService.delete(id);
        return Result.success();

    }

    @PostMapping("/addZone")
    @ApiOperation(value = "新增专区")
    public Result insert(@RequestBody TbZone tbZone){

        int insert = tbZoneService.insert(tbZone);
        return Result.success();
    }
}
